﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class SSFGL_SSFGLExport : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!ProjectPrivate.GetQX("18"))
    {
      Server.Transfer("~\\blank.aspx");
    }
    InitData();
  }

  protected void InitData()
  {
    string sCBSJID = CommonUse.GetID("cbsjid");
    string sKHID = CommonUse.GetID("khid");
    string sJFSJID = CommonUse.GetID("jfsjid");

    if (string.IsNullOrEmpty(sJFSJID) || string.IsNullOrEmpty(sKHID))
    {
      return;
    }
    ConvertSum cs = new ConvertSum();
    SqlDataReader dr = KHXX.GetXX(sKHID);
    if (dr.Read())
    {
      lbKHMC.Text = dr["khmc"].ToString();
      lbKH.Text = dr["kh"].ToString();
      lbJTDZ.Text = dr["xxdz"].ToString();
      lbBQL.Text = "0&nbsp;方";
    }
    dr.Close();

    string sSql = @"select * from sjlr_jfsj a,sys_user b where jfsjid=@0 and a.dlm=b.dlm";
    SqlParameter[] cmdParams = { new SqlParameter("@0", SqlDbType.VarChar, 20) };
    cmdParams[0].Value = sJFSJID;
    dr = DbHelperSQL.ExecuteReader(sSql, cmdParams);
    if (dr.Read())
    {
      lbBH.Text = dr["bh"].ToString();
      lbCPRQ.Text = dr["jfsj"].ToString();
      lbCZY.Text = dr["xm"].ToString();
      lbZDR.Text = dr["xm"].ToString();
    }
    dr.Close();

    sSql = @"select b.* from sjlr_cbsj a,sjlr_bqql b where a.khid=@0 and a.cbsjid=b.cbsjid and cbsj=@1";
    cmdParams = new SqlParameter[2] { new SqlParameter("@0", SqlDbType.VarChar, 20), new SqlParameter("@1", SqlDbType.VarChar, 20) };
    cmdParams[0].Value = sKHID;
    cmdParams[1].Value = lbCPRQ.Text.Substring(0, 10);
    dr = DbHelperSQL.ExecuteReader(sSql, cmdParams);
    if (dr.Read())
    {
      lbYQL.Text = dr["bqql"].ToString() + "&nbsp;方";
      lbDJ.Text = "￥" + dr["jg"].ToString();
      lbBXF.Text = "￥0.00";
      lbJE.Text = "￥" + dr["ssfy"].ToString();
      lbQQJE.Text = "￥0.00";
      lbGXF.Text = "￥0.00";
      lbXJ.Text = "￥" + dr["ssfy"].ToString();
      lbDJQ.Text = "￥0.00";
      lbZJ.Text = cs.ConvertS(dr["ssfy"].ToString()) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;￥" + dr["ssfy"].ToString();
    }
    dr.Close();
  }
}

//lbCPRQ.Text = dr["rq"].ToString();
//lbBH.Text = dr["bh"].ToString();
//lbKHBM.Text = dr["khid"].ToString();
//lbKHMC.Text = dr["khmc"].ToString();
//lbSQJCK.Text = (Convert.ToDouble(dr["scjyk"].ToString()) < 0) ? "0" : string.Format("{0:n}", Convert.ToDecimal(dr["scjyk"].ToString()));
//lbBCYSK.Text = string.Format("{0:n}", Convert.ToDecimal(dr["BCYSK"].ToString()));
//lbBCJQK.Text = string.Format("{0:n}", Convert.ToDecimal(dr["bcjyk"].ToString()));
//lbBCSSK.Text = string.Format("{0:n}", Convert.ToDecimal(dr["bqsj"].ToString()));
//lbZDR.Text = dr["xm"].ToString();
//lbDX.Text = cs.ConvertS(dr["BCYSK"].ToString());
//lbXX.Text = lbBCSSK.Text;
//    string sSql = @"select a.*,convert(varchar,a.jfsj,23) rq,isnull(b.bcjyk,0) scjyk,c.khmc,d.xm
//from sjlr_jfsj a join jcxx_khxx c on  a.khid=c.khid join sys_user d on a.dlm=d.dlm left join 
//(select top 1 khid,bcjyk from sjlr_jfsj
// where jfsj=(select max(jfsj) from sjlr_jfsj where khid=@1 and jfsjid<@0) and khid=@1 order by jfsj desc) b on a.khid=b.khid
//where a.jfsjid=@0";